from django.db import models


class User(models.Model):
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=120)
    level = models.IntegerField(default=1)  # 默认1 表示普通用户  2 VIP用户
    # 优惠券 多对多管理
    coupon = models.ManyToManyField("Coupon", through="User_Coupon")


class Coupon(models.Model):
    sn = models.CharField(max_length=20)
    title = models.CharField(max_length=60)
    limit = models.IntegerField('使用条件')
    money = models.IntegerField('减多少钱')


class Goods(models.Model):
    name = models.CharField('名称', max_length=20)
    price = models.IntegerField('价格')
    store = models.IntegerField('库存')


class User_Coupon(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    coupon = models.ForeignKey(Coupon, on_delete=models.CASCADE)
